import config
from mdcliapi import MajorClient

########################################
def main():
    broker_server = "%s://%s:%d" % (config.PROTOCOL, config.BROKER_IP, config.PORT)
    client = MajorClient(broker_server)

    while 1:
        requests = 3
        for i in xrange(requests):
            request = "Hello world"
            try:
                client.send("echo", request)
            except KeyboardInterrupt:
                print "send interrupted, aborting"
                return

        count = 0
        while count < requests:
            try:
                reply = client.recv()
                print "reply: ", reply
            except KeyboardInterrupt:
                break
            else:
                pass
                # also break on failure to reply:
                # if reply is None:
                #     break
            count += 1
        print "%i requests/replies processed" % count

if __name__ == '__main__':
    main()

